package com.hzhc.controller.sysmanage;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hzhc.annotation.SysTemLog;
import com.hzhc.common.BaseController;
import com.hzhc.entity.SysUserSecurity;
import com.hzhc.enumBean.ResultUtilCodeEnum;
import com.hzhc.service.SysUserSecurityService;
import com.hzhc.utils.ResultUtil;
import com.hzhc.utils.TokenUtil;
import com.hzhc.vo.SysUserSecurityVo;
import lombok.RequiredArgsConstructor;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @author dongcy
 * @date 2024/6/24 14:14
 * @description SysUserSecurityController
 */
@RestController
@RequestMapping("/sysUserSecurity")
@RequiredArgsConstructor
public class SysUserSecurityController extends BaseController {

    private final SysUserSecurityService securityService;

    /**
     * 用户安全设置 list
     * @param request
     * @param vo
     * @return
     */
    @RequestMapping("/getAllList")
    public ResultUtil<List<SysUserSecurityVo>> getAllList(HttpServletRequest request,@RequestBody SysUserSecurityVo vo){
        Page<SysUserSecurity> page = new Page<>(vo.getPageIndex(),vo.getPageSize());
        List<SysUserSecurityVo> list = securityService.getAllList(page,vo);
        return ResultUtil.build(list,page.getTotal(),page.getPages(), ResultUtilCodeEnum.SUCCESS);
    }

    /**
     * 用户安全设置 add
     * @param request
     * @param vo
     * @return
     */
    @PostMapping("/addPasswordSecurity")
    @SysTemLog(operModul = "系统设置-用户安全设置", operType = "ADD", operDesc = "用户安全设置新增", modular = "PC")
    public ResultUtil<T> addPasswordSecurity(HttpServletRequest request,@RequestBody SysUserSecurityVo vo){
        Long userID = TokenUtil.getUserID(request);
        vo.setUserId(userID);
        return securityService.addPasswordSecurity(vo);
    }

    /**
     * 用户安全设置 update
     * @param request
     * @param vo
     * @return
     */
    @PostMapping("/updatePasswordSecurity")
    @SysTemLog(operModul = "系统设置-用户安全设置", operType = "UPDATE", operDesc = "用户安全设置修改", modular = "PC")
    public ResultUtil<T> updatePasswordSecurity(HttpServletRequest request,@RequestBody SysUserSecurityVo vo){
        Long userID = TokenUtil.getUserID(request);
        vo.setUpdateUserId(userID);
        return securityService.updatePasswordSecurity(vo);
    }

    /**
     * 用户安全设置 delete
     * @param id
     * @return
     */
    @GetMapping("/deletePasswordSecurity/{id}")
    public ResultUtil<T> deletePasswordSecurity(@PathVariable Long id){
        return securityService.deletePasswordSecurity(id);
    }

    /**
     * 用户安全设置 启用/禁用
     * @param request
     * @param vo
     * @return
     */
    @RequestMapping("/updateSecurityStatus")
    @SysTemLog(operModul = "系统设置-用户安全设置", operType = "UPDATE", operDesc = "用户安全设置修改", modular = "PC")
    public ResultUtil<T> updateSecurityStatus(HttpServletRequest request,@RequestBody SysUserSecurityVo vo){
        Long userID = TokenUtil.getUserID(request);
        vo.setUpdateUserId(userID);
        return securityService.updateSecurityStatus(vo);
    }



}
